package com.example.lib_cache.datebase;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.example.lib_cache.dao.UserDao;
import com.example.lib_cache.model.User;
import com.example.lib_common.utils.AppGlobals;

/**
 * Created by 张柱 on 2022/4/11
 */

@Database(entities = {User.class}, version = 1)
public abstract class CacheDataBase extends RoomDatabase {
    private static final CacheDataBase database;

    static {
        //创建数据库
        database = Room.databaseBuilder(AppGlobals.getsApplication(), CacheDataBase.class, "db_hw")
                //允许在主线程中执行查询
                .allowMainThreadQueries()
                .build();
    }

    public static CacheDataBase getDataBase() {
        return database;
    }

    public abstract UserDao userDao();
}
